//引入request.js
const {request} =require('./request')
const baseURL='https://api.it120.cc'
const vipUrl='hjl'

//抛出各种业务接口
module.exports={
  //商品类别接口
  getGoodsCateApi:()=>{
    return request('/shop/goods/category/all','GET')
  },
  //首页轮播图接口
  getBannerApi:(type='index')=>{
    return request('/banner/list','GET',{type})
  },
  //商品列表
  /**
   * 
   * @param {Object} data {miaosha:true,pingtuan:true,....}
   */
  getGoodsListApi:(data={})=>{
    return request('/shop/goods/list/v2','POST',data)
  },
  //搜索接口
  //检测token是否有效
  checkTokenValidApi:(token)=>{
    return request('/user/check-token','GET',{token})
  },
  //自动注册与登录的接口
  authRegAndLoginApi:(code)=>{
    return request('/user/wxapp/authorize','POST',{code})
  },
  //用户详情接口
  getUserDetailApi:(token)=>{
    return request('/user/detail','GET',{token})
  },
  //更新用户接口
  updateUserInfoApi:(data={})=>{
    return request('/user/modify','POST',data)
  },
  //动态获取会员码
  getMemberCodeApi:(token)=>{
    return request('/user/dynamicUserCode','GET',{token})
  },
  //图片上传
  /**
   * 
   * @param {String} token  
   * @param {String} tempFiles 上传的临时文件路径
   * @param {String} expireHours  多长时间后自动删除服务器文件，不指定则不删除
   */
  uploadFile:(token,tempFiles,expireHours='')=>{

    //const url=`基地址/专属域名/上传地址`
    const url=`${baseURL}/${vipUrl}/dfs/upload/file`
    return new Promise((resolve,reject)=>{
      wx.uploadFile({
        filePath:tempFiles,
        name: 'upfile',
        url,
        formData:{
          token,
          expireHours
        },
        success(res) {
          resolve(JSON.parse(res.data))
        },
        fail(err) {
          reject(err)
        }
      })
    })

  }
  
}